# 3.33 Compass ## 3.33.1 Overview The AK8975 module is adopted to read direction values. According to these values, the OLED displays different arrows. ## 3.33.2 Test Code ### 3.33.2.1 Code Flow ![6-33-2-1](./media/6-33-2-1.png) ### 3.33.2.2 Build Code There are two ways to upload the code: directly open the code file we provide; or manually build blocks. **Directly open the code file we provide:** 1. Click ![](./media/j68.png) and choose `Load from your computer` ![](./media/j67.png) 2. We have already downloaded the codes on computer desktop, so open the file and choose `3-33-compass.sb3` **Manually build blocks:** 1. Build the two basic blocks:![6-1-4-1-1](./media/6-1-4-1-1.png) 2. Initialize AK8975 module and OLED display, declare a variable “direction”. ![](./media/6-33-2-2-1.png) 3. Clear the OLED, and assign the direction value of AK8975 to the variable *direction* ![](./media/6-33-2-2-2.png) 4. Add a ![j25](./media/j25.png) to determine whether 340 < direction < 360. If yes, OLED shows “↑”. Block condition: direction > 340 and direction < 360 ![](./media/6-33-2-2-3.png) 5. Duplicate blocks and determine whether direction > 230 and direction < 250. If yes, OLED shows “→”. 6. If direction > 140 and direction < 170, OLED shows “↓”. 7. If direction > 70 and direction < 90, OLED shows “←”. ![](./media/6-33-2-2-4.png) 8. Add an OLED refresh block and add a delay of 0.5S. **Complete Test Code** ![6-33-2-2](./media/6-33-2-2.png) ### 3.33.2.3 Test Result After uploading code, the arrow on the OLED will nearly point to the South. Move the coding box and you will see the direction changes.